﻿namespace ProtocolTool
{
    partial class Program
    {
        //Enum
        public static readonly string Filepath_Enum = @"ProtocolEnum.cs";

        public static readonly string Template_Enum = @"
/*
本文件由工具自动生成 请勿手动修改！！！
*/

using System;
using System.Collections.Generic;

namespace ServerBase.Protocol
{
$Enum$
}

";

        //ClassId
        public static readonly string Filepath_ClassId = @"ProtocolId.cs";

        public static readonly string Template_ClassId = @"
/*
本文件由工具自动生成 请勿手动修改！！！
*/

using System;
using System.Collections.Generic;

namespace ServerBase.Protocol
{
    public enum EProtocolId : short
    {
        UNKNOWN_TYPE = 0,

$ClassId$
    }
}

";

        //ClassBase
        public static readonly string Filepath_ClassBase = @"ProtocolClass.cs";

        public static readonly string Template_ClassBase = @"
/*
本文件由工具自动生成 请勿手动修改！！！
*/

using System;
using System.Collections.Generic;

namespace ServerBase.Protocol
{
$Class$
}

";

        //ClassSerialization
        public static readonly string Filepath_ClassSerialization = @"ProtocolSerialization.cs";

        public static readonly string Template_ClassSerialization = @"
/*
本文件由工具自动生成 请勿手动修改！！！
*/

using System;
using System.Collections.Generic;

namespace ServerBase.Protocol
{
$Class$
}

";

        

        //ClassDump
        public static readonly string Filepath_ClassDump = @"ProtocolDump.cs";

        public static readonly string Template_ClassDump = @"
/*
本文件由工具自动生成 请勿手动修改！！！
*/

using System.Text;
using ServerBase.BaseManagers;

namespace ServerBase.Protocol
{
    public static class ProtocolDump
    {
        public static string Dump(EProtocolId id, byte[] buffer)
        {
            var sb = new StringBuilder();
            switch (id)
            {
$Class$
                default:
                    return """";
            }
            return sb.ToString();
        }
    }
}

";


        //ClassReqRsp
        public static readonly string Filepath_ClassReqRsp = @"ProtocolReqRsp.cs";

        public static readonly string Template_ClassReqRsp = @"
/*
本文件由工具自动生成 请勿手动修改！！！
*/

using System;
using System.Collections.Generic;

namespace ServerBase.Protocol
{
    public static partial class ProtocolExtensions
    {
$ClassReqRsp$
    }
}

";

        //ClassReqRsp2
        public static readonly string Filepath_ClassReqRsp2 = @"ProtocolReqRsp2.cs";

        public static readonly string Template_ClassReqRsp2 = @"
/*
本文件由工具自动生成 请勿手动修改！！！
*/

using System;
using System.Collections.Generic;
using UtilPublic.Serialization;

namespace ServerBase.Protocol
{
    public static partial class ProtocolExtensions
    {
$ClassReqRsp$
    }
}

";

        //ClassGet
        public static readonly string Filepath_ClassGet = @"ProtocolClassGet.cs";

        public static readonly string Template_ClassGet = @"
/*
本文件由工具自动生成 请勿手动修改！！！
*/

using System;
using System.Collections.Generic;

namespace ServerBase.Protocol
{
    public static partial class ProtocolExtensions
    {
        public static T GetClass<T>(this byte[] buffer) where T : ProtocolMsgBase, new()
        {
            var result = new T(); 
            result.Unserialize(buffer); 
            return result;
        }
        public static ProtocolMsgBase GetMsgBase(this byte[] buffer)
        {
            if (buffer.Length < 2)
            {
                return new ProtocolMsgBase();
            }
            EProtocolId pid = (EProtocolId)System.BitConverter.ToUInt16(buffer, 0);
            return pid.GetMsgBase(buffer);
        }
        public static ProtocolMsgBase GetMsgBase(this EProtocolId pid, byte[] buffer)
        {
            switch (pid)
            {
$ClassGet$
                default: return new ProtocolMsgBase();
            }
        }
    }
}

";


    }
}